package com.session05;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class TestFileCopy {
    public static void main(String[] args) {
        FileInputStream fin = null;
        FileOutputStream fout = null;

        try {
            fin = new FileInputStream("test.txt");
            fout = new FileOutputStream("D:/AAAA/a.txt");

            //每次读一个字节数组，然后把这个字节数组写出去
            //注意：要记录每次读取了多少个有效数据输出时只输出这么多个
            byte[] b = new byte[1024];
            int length = 0;
            while ((length = fin.read(b)) != -1) {
                fout.write(b,0,length);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fin != null) {
                try {
                    fin.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fout!=null){
                try {
                    fout.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
